package com.lan.parse;

import com.lan.ScriptContext;
import com.lan.antlr.ScriptBaseListener;
import com.lan.antlr.ScriptParser;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.apache.commons.lang3.StringUtils;

public class TestScriptBaseListener extends ScriptBaseListener {

    private ScriptContext context;

    public TestScriptBaseListener(ScriptContext context) {
        this.context = context;
    }

    private void print(ParserRuleContext ctx, String name) {
        System.out.println(ctx.getRuleIndex() + " :   " + ctx.toString() + "   " + (StringUtils.isNotBlank(name) ? name : "") + " " + (StringUtils.isNotBlank(ctx.getText()) ? ctx.getText() : ""));
    }

    @Override
    public void enterProg(ScriptParser.ProgContext ctx) {
        print(ctx, "enterProg");
    }

    @Override
    public void enterBlockStatements(ScriptParser.BlockStatementsContext ctx) {
        print(ctx, "enterBlockStatements");
    }

    @Override
    public void enterBlock(ScriptParser.BlockContext ctx) {
        print(ctx, "enterBlock");
    }


    @Override
    public void enterBlockStatement(ScriptParser.BlockStatementContext ctx) {
        print(ctx, "enterBlockStatement");
    }


    @Override
    public void enterPrimary(ScriptParser.PrimaryContext ctx) {
        print(ctx, "enterPrimary");
    }

    @Override
    public void enterVariableDeclarator(ScriptParser.VariableDeclaratorContext ctx) {
        print(ctx, "enterVariableDeclarator");
    }

    @Override
    public void enterVariableDeclaratorId(ScriptParser.VariableDeclaratorIdContext ctx) {
        print(ctx, "enterVariableDeclaratorId");
    }

    @Override
    public void enterForControl(ScriptParser.ForControlContext ctx) {
        print(ctx, "enterForControl");
    }

    @Override
    public void enterForInit(ScriptParser.ForInitContext ctx) {
        print(ctx, "enterForInit");
    }

    @Override
    public void enterVariableInitializer(ScriptParser.VariableInitializerContext ctx) {
        print(ctx, "enterVariableInitializer");
    }


    @Override
    public void enterJson(ScriptParser.JsonContext ctx) {
        print(ctx, "enterJson");
    }


    @Override
    public void enterStr(ScriptParser.StrContext ctx) {
        print(ctx, "enterStr");
    }

    @Override
    public void enterObj(ScriptParser.ObjContext ctx) {
        print(ctx, "enterObj");
    }

    @Override
    public void enterArr(ScriptParser.ArrContext ctx) {
        print(ctx, "enterArr");
    }

    @Override
    public void enterPair(ScriptParser.PairContext ctx) {
        print(ctx, "enterPair");
    }

    @Override
    public void enterFunction(ScriptParser.FunctionContext ctx) {
        print(ctx, "enterFunction");
    }

    @Override
    public void enterParameters(ScriptParser.ParametersContext ctx) {
        print(ctx, "enterParameters");
    }

    @Override
    public void enterFunctionCall(ScriptParser.FunctionCallContext ctx) {
        print(ctx, "enterFunctionCall");
    }

    @Override
    public void enterName(ScriptParser.NameContext ctx) {
        print(ctx, "enterName");
    }

    @Override
    public void enterStatement(ScriptParser.StatementContext ctx) {
        print(ctx, "enterStatement");
    }

    @Override
    public void visitErrorNode(ErrorNode node) {
        System.out.println(node.getText());
    }
}
